/*
 * Project CHEN Rendering Engine : /halton.cpp
 * Created: 2020-12-16, Last modified:  2021-02-16
 * 
 * This file is (temporarily) deprecated.
 * 
 * Copyright (C) 2021 Hineven (hineven@pku.edu.cn)
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
/*
#include "halton.hpp"
namespace chen {
void HaltonSampler::startSample() 
{
    current_sample = 0;
}

Sampler * HaltonSampler::clone() 
{
    HaltonSampler * h = new HaltonSampler();
    h->startSample();
    h->current_sample = current_sample;
    return h;
}

Float radicalInverse2 (unsigned l) {
    l = (l>>16)|(l<<16);
    l = ((l>>8)&0x00ff00ffu)|((l<<8)&0xff00ff00u);
    l = ((l>>4)&0x0f0f0f0fu)|((l<<4)&0xf0f0f0f0u);
    l = ((l>>2)&0x33333333u)|((l<<2)&0xccccccccu);
    l = ((l>>1)&0x55555555u)|((l<<1)&0xaaaaaaaau);
    Fbits r;
    r.f = 1.0;
#if (Float_cwidth >= 32)
    r.i |= l << (Float_cwidth-32);
#else
    r.i |= l >> (32-Float_cwidth);
#endif
    return r.f-1;
}
Float radicalInverseD (unsigned l, int d) {
    Float ret = 0;
    int i = 0;
    char seqbuf[32];
    while(l) seqbuf[i++] = l%d, l/=d;
    while(i--) ret = ret/d+seqbuf[i];
    ret = ret/d;
    assert(ret < 1 && ret >= 0);
    return ret;
}
Float HaltonSampler::gen () {
    return radicalInverse2(current_sample++);
}
Point2 HaltonSampler::gen2D () {
    current_sample ++;
    Point2 ret = Point2(radicalInverse2(current_sample), radicalInverseD(current_sample, 3));
    return ret;
}
Float* HaltonSampler::genArray (int n) {
    Float * ret = new Float[n];
    for(int i = 0; i<n; i++) ret[i] = gen();
    return ret;
}
Point2* HaltonSampler::gen2DArray (int n) {
    Point2 * ret = new Point2[n];
    if(n > 31) {
        for(int i = 0; i<n; i++) {
            if(rand()&1) ret[i] = Point2((i+0.5)/n, gen());
            else ret[i] = Point2(gen(), (i+0.5)/n);
        }
    } else {
        for(int i = 0; i<n; i++) ret[i] = gen2D();
    }
    return ret;
}

HaltonSampler::~HaltonSampler() 
{
    
}
}*/